{extend name="layout/default" /}

{block name="content"}
<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default panel-intro">
            {include file="yxerp/common/subnavbar" /}
            <div class="panel-body">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade active in" id="one">
                        <div class="widget-body no-padding">
                            <div id="toolbar" class="toolbar">
                                {:build_toolbar('refresh')}
                                <div class="dropdown btn-group {:$auth->check('permission/add')?'':'hide'}">
                                    <a href="#" class="btn btn-primary btn-success btn-add" data-toggle="dropdown"><i class="fa fa-plus"></i> {:__('Add')}</a>
                                    <ul class="dropdown-menu text-left" role="menu">
                                        <li><a class="btn btn-default btn-dialog" href="{:url('permission/add')}" title="{:__('Add Permission')}"><i class="fa fa-plus"></i> {:__('Add Permission')}</a></li>
                                        <li><a class="btn btn-default btn-dialog" href="{:url('permissiongroup/add')}" title="{:__('Add Permission Group')}"><i class="fa fa-plus"></i> {:__('Add Permission Group')}</a></li>
                                    </ul>
                                </div>
                                <a href="javascript:;" class="btn btn-default btn-dialog {:$auth->check('permissiongroup/index')?'':'hide'}" title="{:__('Manage Permission Groups')}" data-url="{:url('permissiongroup/index')}" data-width="800" data-height="600"><i class="fa fa-folder-o"></i> {:__('Manage Groups')}</a>
                            </div>
                            <div class="row">
                                <div class="col-md-2">
                                    <div class="panel panel-default">
                                        <div class="panel-heading">
                                            {:__('Permission Groups')}
                                        </div>
                                        <div class="panel-body">
                                            <ul class="nav nav-pills nav-stacked">
                                                <li class="active"><a href="javascript:;" data-group-id="0">{:__('All Groups')}</a></li>
                                                {foreach name="groupList" item="group"}
                                                <li><a href="javascript:;" data-group-id="{$group.id}">{$group.name}</a></li>
                                                {/foreach}
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-10">
                                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap" width="100%">
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
    var Table;
    $(function () {
        // 初始化表格
        Table = $("#table").bootstrapTable({
            url: '{:url("permission/index")}',
            pk: 'id',
            sortName: 'id',
            pagination: true,
            commonSearch: false,
            search: false,
            columns: [
                [
                    {field: 'state', checkbox: true},
                    {field: 'id', title: 'ID', operate: 'LIKE'},
                    {field: 'name', title: '{:__("Name")}', operate: 'LIKE'},
                    {field: 'group.name', title: '{:__("Group")}', operate: 'LIKE'},
                    {field: 'code', title: '{:__("Code")}', operate: 'LIKE'},
                    {field: 'type', title: '{:__("Type")}', searchList: {menu: '{:__("Menu")}', file: '{:__("File")}', button: '{:__("Button")}', other: '{:__("Other")}'}},
                    {field: 'data_scope_text', title: '{:__("Data Scope")}', operate: false},
                    {field: 'status', title: '{:__("Status")}', searchList: {normal: '{:__("Normal")}', hidden: '{:__("Hidden")}'}},
                    {field: 'operate', title: '{:__("Operate")}', table: Table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
                        {
                            name: 'departments',
                            text: '{:__("Departments")}',
                            title: '{:__("Assign to Departments")}',
                            icon: 'fa fa-building',
                            classname: 'btn btn-xs btn-info btn-dialog',
                            url: 'permission/departments',
                        },
                        {
                            name: 'positions',
                            text: '{:__("Positions")}',
                            title: '{:__("Assign to Positions")}',
                            icon: 'fa fa-sitemap',
                            classname: 'btn btn-xs btn-info btn-dialog',
                            url: 'permission/positions',
                        },
                        {
                            name: 'employees',
                            text: '{:__("Employees")}',
                            title: '{:__("Assign to Employees")}',
                            icon: 'fa fa-users',
                            classname: 'btn btn-xs btn-info btn-dialog',
                            url: 'permission/employees',
                        },
                        {
                            name: 'admins',
                            text: '{:__("Admins")}',
                            title: '{:__("Assign to Admins")}',
                            icon: 'fa fa-user-secret',
                            classname: 'btn btn-xs btn-info btn-dialog',
                            url: 'permission/admins',
                        }
                    ]}
                ]
            ]
        });

        // 权限组切换
        $(document).on("click", ".nav-pills a", function () {
            var groupId = $(this).data("group-id");
            $(this).closest("li").addClass("active").siblings().removeClass("active");
            Table.bootstrapTable('refresh', {
                query: {
                    group_id: groupId
                }
            });
            return false;
        });

        // 为表格绑定事件
        Table.api.bindevent(Table);
    });
</script>
{/block} 